   <?php

//This is the directory where images will be saved
$target = "../images/profile/";
$target = $target . basename( $_FILES['photo']['name']);
$path = "../images/profile/";
$rpath = "images/profile/";

//This gets all the other information from the form
$name = $_POST['user_id'];
$pic = ($_FILES['photo']['name']);




// Connects to your Database
include "../scripts/connectDB.php";

//Writes the information to the database
mysql_query("UPDATE users SET photo = '$rpath$pic' WHERE user_id = '$_POST[user_id]'");

//Writes the photo to the server

if ((($_FILES["photo"]["type"] == "image/gif")
|| ($_FILES["photo"]["type"] == "image/jpeg")
|| ($_FILES["photo"]["type"] == "image/pjpeg"))
&& ($_FILES["photo"]["size"] < 9999999999))


  {
  if ($_FILES["photo"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["photo"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["photo"]["name"] . "<br />";
    echo "Type: " . $_FILES["photo"]["type"] . "<br />";
    echo "Size: " . ($_FILES["photo"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["photo"]["tmp_name"] . "<br />";

    if (file_exists("TEMP/" . $_FILES["photo"]["name"]))
      {
      echo $_FILES["photo"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["photo"]["tmp_name"],
      "$path" . $_FILES["photo"]["name"]);
      echo "Stored in: " . "$path" . $_FILES["photo"]["name"];
	  
	  
	  }
    }
  }
else
  {
  echo "Invalid file";
  }
  
?>